package p270jp.pxv.android.view;

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.view.View;
import androidx.viewpager.widget.ViewPager;
import p018ai.C0218e;
import p094d4.PagerAdapter;
import p270jp.pxv.android.R;

/* renamed from: jp.pxv.android.view.PageControl */
/* loaded from: classes2.dex */
public class PageControl extends View {

    /* renamed from: a */
    public int f19620a;

    /* renamed from: b */
    public int f19621b;

    /* renamed from: e */
    public int f19624e;

    /* renamed from: f */
    public int f19625f;

    /* renamed from: g */
    public Paint f19626g = new Paint();

    /* renamed from: c */
    public int f19622c = getResources().getDimensionPixelSize(R.dimen.control_padding);

    /* renamed from: d */
    public int f19623d = getResources().getDimensionPixelSize(R.dimen.control_size);

    /* renamed from: jp.pxv.android.view.PageControl$a */
    /* loaded from: classes2.dex */
    public class C4388a extends ViewPager.C0900k {
        public C4388a() {
        }

        @Override // androidx.viewpager.widget.ViewPager.AbstractC0898i
        /* renamed from: Y */
        public void mo943Y(int i) {
            PageControl pageControl = PageControl.this;
            pageControl.f19621b = i;
            pageControl.invalidate();
        }
    }

    public PageControl(Context context, AttributeSet attributeSet) {
        super(context, attributeSet, 0, 2131887295);
        this.f19626g.setAntiAlias(true);
        this.f19626g.setStyle(Paint.Style.FILL);
        TypedArray obtainStyledAttributes = getContext().obtainStyledAttributes(attributeSet, C0218e.f748f, 0, 2131887295);
        this.f19624e = obtainStyledAttributes.getColor(0, 0);
        this.f19625f = obtainStyledAttributes.getColor(1, 0);
        obtainStyledAttributes.recycle();
    }

    @Override // android.view.View
    public void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        int i = this.f19623d;
        int i2 = this.f19620a;
        int width = (getWidth() / 2) - ((((i2 - 1) * this.f19622c) + (i * i2)) / 2);
        int height = getHeight() / 2;
        int i3 = 0;
        while (i3 < this.f19620a) {
            this.f19626g.setColor(i3 == this.f19621b ? this.f19624e : this.f19625f);
            int i4 = this.f19623d;
            canvas.drawCircle((float) ((i4 / 2) + width), (float) ((i4 / 2) + height), (float) i4, this.f19626g);
            width += this.f19622c;
            i3++;
        }
    }

    public void setupWithViewPager(ViewPager viewPager) {
        PagerAdapter adapter = viewPager.getAdapter();
        if (adapter != null) {
            this.f19620a = adapter.mo938c();
            this.f19621b = viewPager.getCurrentItem();
            viewPager.m10517b(new C4388a());
            invalidate();
            return;
        }
        throw new IllegalArgumentException("ViewPager does not have a PagerAdapter set");
    }
}
